// read .env variables
require('dotenv').config()

const logger = require('./helper/logger')
const app = require('./app')
const {
  APP_API_HOST,
  APP_API_PORT,
} = require('./config')

const server = app.listen(APP_API_PORT)

logger.info('NODE_ENV =', process.env.NODE_ENV)

process.on('unhandledRejection', (reason, p) => {
  logger.error('Unhandled Rejection at: Promise ', p, reason)
})

server.on('listening', () => logger.info(`API started on http://${APP_API_HOST}:${APP_API_PORT}`))

module.exports = server
